package com.afc.struts.bustle.products;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.afc.struts.Action;
import com.afc.struts.bustle.data.ProductDao;
import com.afc.struts.bustle.model.ProductDto;
import com.afc.struts.bustle.product.ProductForm.DefaultProductForm;

public class ProductsUpdateAction implements Action<ProductsForm>
{
  @Override
  public String execute(ProductsForm anActionForm, HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletException
  {
    ProductDto product = ProductDao.getInstance().retrieve(anActionForm.getSelectedProductId());
    if (product != null)
    {
      aRequest.setAttribute("form", new DefaultProductForm(product.getIdProduct(), product.getProductType(), product.getName(), product.getPrice(), product.getDescription(), product.getCreationDate(), product.getLimitedDate(), product.getImage(), product.getProvider()));
      return "/pages/productUpdate.jsp";
    }
    return null;
  }
}
